<script>
    <?php use yii\helpers\Url;$this->beginBlock('js_end') ?>
    <?php $height = isset($height) ? $height : '600px'  ?>
    <?php if(!isset($option) || in_array('c', $option)):?>
    //添加
    $(document).on('click', '.create', function () {
        layer.open({
            type: 2,
            title: '新增',
            shadeClose: true,
            shade: 0.4,
            area: ['50%', '<?=$height?>'],
            content: '<?=Url::toRoute('create')?>',
            end: function () {
                $.pjax.reload({container: "#centerView"});
            }
        });
    });
    <?php endif?>
    <?php if(!isset($option) || in_array('u', $option)):?>
    //修改
    $(document).on('click', '.update', function () {
        var id = $(this).closest('tr').data('key');
        layer.open({
            type: 2,
            title: '修改',
            shadeClose: true,
            shade: 0.4,
            area: ['50%', '600px'],
            content: '<?=Url::toRoute('update')?>?id=' + id,
            end: function () {
                $.pjax.reload({container: "#centerView"});
            }
        });

    });
    <?php endif?>
    <?php if(!isset($option) || in_array('d', $option)):?>
    //删除
    $(document).on('click', '.delete', function () {
        var id = $(this).closest('tr').data('key');
        layer.confirm('确认删除吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: '<?=Url::toRoute('delete')?>',
                data: {id: id},
                dataType: 'json'
            })
                .done(function (msg) {
                    if (msg['status']) $.pjax.reload({container: "#centerView"});
                    if (msg['msg']) layer.msg(msg['msg'], {icon: 1});
                    else layer.msg('删除成功', {icon: 1});
                });
        }, function () {
            layer.closeAll();
        });
    });
    <?php endif?>
    <?php if(!empty($option) && in_array('v', $option)):?>
    $(document).on('click', '.detail', function () {
        var id = $(this).closest('tr').data('key');
        console.log(11);
        layer.open({
            type: 2,
            title: '详情',
            shadeClose: true,
            shade: 0.4,
            shift: 2,
            area: ['50%', '460px'],
            content: '<?=Url::toRoute('view')?>?id=' + id,
            end: function () {
                $.pjax.reload({container: "#centerView"});
            }
        });

    });
    <?php endif?>
    <?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_end'], \yii\web\View::POS_END); ?>